﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ColorPanelChange : MonoBehaviour {

	private TextMesh myTextMesh;
	private List<int> colorCode = new List<int>();
	private string setText;

	// Use this for initialization
	void Start () {
		myTextMesh = GetComponent<TextMesh>();
	}
	
	// Update is called once per frame
	void Update () {
		myTextMesh.text = "";
		if(colorCode.Count > 0)
			writeAsterisk();
		myTextMesh.text = setText;
	}

	void writeAsterisk()
	{
		for(int i = 0; i < colorCode.Count; i++)
			if(i == 0)
				setText = "*";
			else
				setText += "*";

		if(colorCode.Count >= 5)
			checkColorCode();
	}

	public void Addsterisk(string color)
	{
		switch(color)
		{
			case "Red":
			colorCode.Add(1);
			break;
			case "Purple":
			colorCode.Add(2);
			break;
			case "Blue":
			colorCode.Add(3);
			break;
			case "Green":
			colorCode.Add(4);
			break;
			case "Yellow":
			colorCode.Add(5);
			break;
		}
	}

	void checkColorCode()
	{
		bool combo = true;
		for(int i = 0; i < colorCode.Count; i++)
			if(colorCode[i] != i + 1)
			{
				combo = false;
				break;
			}

		if(combo)
		{
			GameObject.Find("MenuManager").GetComponent<MusicManager>().PlaySoundEffect(Resources.Load("SFX/colo_conf", typeof(AudioClip)) as AudioClip);
			Dialoguer.StartDialogue(DialoguerDialogues.FP_ColorPanel_Correct);
		}
		else
			Debug.Log("Wrong Combo!");

		colorCode.Clear();
		setText = "";
	}
}
